<?php
namespace Admin\Controller;

/**
 * 表单控件控制器
 * Class FormCtrController
 * @package Admin\Controller
 */
class FormCtrController extends AbstractController {
	
	protected $Form;

	public function _initialize(){
		$FormID = !empty(I("FormID")) ? (int)I("FormID") : (int)$_GET["FormID"];
		$this->assign("FormID",$FormID);
		$this->Form = D('Formcontrol');
    }
    
    public function index(){
    	$res = $this->Form->MyshowList();
		$this->assign("list",$res['list']);
    	$this->assign("page",$res['page']);
		$this->display();
    }
    
    public function add(){
    	if(IS_POST){
 			$result = $this->Form->Myupadd();
 			if($result['state'] == 1 && !empty($result)){
				$this->success($result['msg']);
			}else if($result['state'] == 0 && !empty($result)){
				$this->error($result['msg']);
			}
    	}else{
    		//$res = $this->Form->getFormList();
    		//$this->assign("formList",$res);
    		$res = $this->Form->getFormCName();
    		$this->assign("formCName",$res);
    		$this->display("Formctr/save");
    	}
    }
    
    public function edit(){
    	if(I('ID')){
			$res = $this->Form->Myshow(array("ID" => (int)I('ID')));
			$formList = $this->Form->getFormList();
    		$this->assign("formList",$formList);
			$this->assign("editdata",$res);
		}
		$res = $this->Form->getFormCName();
    	$this->assign("formCName",$res);
		$this->display("Formctr/save");
    }
    
    public function update(){
    	if(IS_POST){
    		$result = $this->Form->Myupdata();
    		if($result['state'] == 1 && !empty($result)){
				$this->success($result['msg']);
			}else if($result['state'] == 0 && !empty($result)){
				$this->error($result['msg']);
			}
    	}
    }
    
    public function delete(){
		if(I('ID')){
			$result = $this->Form->Mydelet();
    		if($result['state'] == 1 && !empty($result)){
				$this->success($result['msg']);
			}else if($result['state'] == 0 && !empty($result)){
				$this->error($result['msg']);
			}
		}
    }
    
    public function getFormCtrList(){
    	if(I('ID')){
    		$result = $this->Form->getFormCtrList();
    		echo $result;
    	}
    }
    
    
}